<!--
 * @Description: 
 * @Version: 2.0
 * @Autor: chentingyu
 * @Date: 2022-03-17 16:56:55
 * @LastEditors: chentingyu
 * @LastEditTime: 2022-03-18 15:47:15
-->
<template>
  <div>
    <!-- <keep-alive > -->
    <router-view></router-view>
    <!-- </keep-alive> -->
  </div>
</template>

<script>
import { mapMutations, mapState } from "vuex";
import SettingPwd from "./views/User/SettingPwd";

export default {
  components: {
    SettingPwd,
  },
  data() {
    return {
      setPwd: false,
    };
  },
  computed: {
    ...mapState(["userInfo"]),
    type() {
      if (this.noUser) return 3;
      return this.userInfo.username !== "root" ? 0 : 1;
    },
    isManager() {
      return this.type === 1;
    },
    isStudent() {
      return this.type === 0;
    },
    noUser() {
      return typeof this.userInfo?.username != "string";
    },
  },
  methods: {
    ...mapMutations(["logout", "syncState", "syncData"]),
    async userLogout() {
      this.$confirm("确认退出系统?", "退出系统", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        closeOnClickModal: false,
        type: "info",
      })
        .then(() => {
          this.logout();
          this.$router.push("/login");
          this.$message.success("成功退出");
        })
        .catch(() => {
          this.$message.warning("已取消");
        });
    },
  },
  created() {
    this.syncState();
    if (this.noUser) this.$router.replace("/login");
  },
  watch: {
    "$store.state": {
      handler() {
        this.syncData();
      },
      deep: true,
    },
  },
};
</script>

<style>
body {
  user-select: none;
  margin: none;
  border: none;
  padding: none;
}
@media screen and (max-width: 480px) {
  body .el-message-box__wrapper .el-message-box {
    width: inherit;
  }
}



</style>
